package com.xyw.code.efficient_programming.lambda.method;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * Created by xuyiwei on 2020/1/6 11:35
 */
public class LambdaMethod {

    public static List<String> array = new ArrayList<>();

    static {
        array.add("a");array.add("b");array.add("c");array.add("d");
        array.add("e");array.add("f");array.add("g");array.add("h");
        array.add("i");array.add("j");array.add("k");array.add("n");
    }

    /**
     * 指向静态方法的方法引用
     */
    public void lambdaMethod1(){
        Consumer<String> consumer = (String s) -> Integer.parseInt(s);
        Consumer<String> consumer1 = Integer::parseInt;
    }

    /**
     * 指向任意类型实例方法的方法引用
     */
    public void lambdaMethod2(){
        Consumer<String> consumer = (String s) -> s.length();
        Consumer<String> consumer1 = String::length;
    }

    /**
     * 指向现有对象的方法引用
     */
    public void lambdaMethod3(){
        Consumer<String> consumer = (String s) -> array.add(s);
        Consumer<String> consumer1 = array::add;
    }
}
